package sk.model;

public class Player {

	private String preName, surName;
	private int id;

	public Player(String preName, String surName, int id) {
		if (preName.contains("?") || surName.contains("?")
			|| preName.contains("%") || surName.contains("%")
			|| preName.contains("&") || surName.contains("&")
			|| preName.contains("!") || surName.contains("!")
			|| preName.contains("~") || surName.contains("~")) {
			throw new DaLaftWosFoischException();
		}
		this.preName = preName;
		this.surName = surName;
		this.id = id;
	}

	public Player(String string) {
		String[] tokens = string.split("&");
		preName = tokens[0];
		surName = tokens[1];
		id = Integer.parseInt(tokens[2]);
	}

	public int getId() {
		return id;
	}

	public String getPreName() {
		return preName;
	}

	public String getSurName() {
		return surName;
	}

	@Override
	public String toString() {
		return preName + "&" + surName + "&" + id;
	}

	@Override
	public boolean equals(Object o) {
		if (o == null) {
			return false;
		}
		if (o.getClass() != Player.class) {
			return false;
		}
		Player other = (Player) o;
		if (other.id == id) {
			return true;
		} else {
			return false;
		}
	}

	public String getName() {
		return preName + " " + surName.charAt(0);
	}

}
